package com.atguigu.gmall.product;

import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.util.ClassUtils;

/**
 * @Author: lx
 * @Time: 15:45
 * @Description:
 */
//@SpringBootTest(classes = ServiceProductApplication.class)
//@SpringBootTest
public class UploadFile {

    //上传图片到文件系统
    public static void main(String[] args) throws Exception {
        //1:引入坐标

        String path = ClassUtils.getDefaultClassLoader()
                .getResource("fdfs_client.conf").getPath();
        //流：只能读取绝对路径  不认识相对路径
        ClientGlobal.init(path);
        //2:上传连接请求  找跟踪器
        TrackerClient trackerClient = new TrackerClient();
        TrackerServer trackerServer = trackerClient.getConnection();

        //3:连接存储节点Storage
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,null);

        //4:上传图片
        String file_id = storageClient1.upload_file1
                ("D:\\尚品汇商城\\资料\\图片\\三星\\5aa36f9a1e4312d5.jpg", "jpg", null);

        System.out.println("http://192.168.200.128:8080/" +file_id);

        //  http://192.168.200.128:8080/group1/M00/00/00/wKjIgF-yorSAYLoIAAT8_AoEzOU126.jpg

        //byte[] bytes = storageClient1.download_file1(file_id);
    }

}
